package com.utils.itext;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;

import org.xhtmlrenderer.pdf.ITextFontResolver;
import org.xhtmlrenderer.pdf.ITextRenderer;

import com.lowagie.text.pdf.BaseFont;

public class FlyingSausePdf {
	public static void main(String[] args) throws Exception {
		String outputFile = "firstdoc.pdf";
		OutputStream os = new FileOutputStream(outputFile);
		ITextRenderer renderer = new ITextRenderer();

		String html = "/home/sanshang/Develop/trunk/trunk/sango/src/main/java/com/utils/itext/image.html";
		String url = new File(html).toURI().toURL().toString();
		renderer.setDocument(url);
		// 解决中文支持问题
		ITextFontResolver fontResolver = renderer.getFontResolver();
		fontResolver.addFont("/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType/utkal.ttf",
				BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
		// 解决图片的相对路径问题
		renderer.getSharedContext().setBaseURL("file:/home/sanshang/");

		renderer.layout();
		renderer.createPDF(os);

		os.close();
		System.out.println("生成成功！");
	}
}
